#include	<stdio.h>
#include	"mxml.h"

int main(int argc, char **argv)
{
    FILE *fp = fopen("myxml.xml","r");
    //加载XML文件
    /**
     * mxml_node_t *mxmlLoadFile(mxml_node_t *top, FILE *fp, mxml_load_cb_t cb);用来加载xml文件
     * 参数1：top node   null  for  any
     * 参数2：从哪儿读取 通常是fp
     * 参数3：回调函数或者常数  
    */
    mxml_node_t *xml = mxmlLoadFile(NULL,fp,MXML_NO_CALLBACK);
    mxml_node_t     *book = NULL;
    mxml_node_t     *title = NULL;
    /**
     * mxml_node_t *mxmlFindElement(mxml_node_t *node,              
     *                                                                          mxml_node_t *top,                
     *                                                                          const char *element,        *************Element name or NULL for any
     *                                                                          const char *attr,                    *************NULL for none
     *                                                                          const char *value,              ***************Attribute value, or NULL for any
     *                                                                          int descend);     ***************************MXML_DESCEND, MXML_NO_DESCEND, or MXML_DESCEND_FIRST
    */
    book = mxmlFindElement(xml,xml,"book","category",NULL,MXML_DESCEND);
    while(book)
    {
        title = mxmlFindElement(book,xml,"title",NULL,NULL,MXML_DESCEND);
            if( title == NULL)
            {
                printf("title not found\n");
                break;
            }
            else
            {
                printf("book'title is %s\n",mxmlGetText(title,NULL));
                printf(" book' category:%s\n",mxmlElementGetAttr(book,"category"));
                book = mxmlFindElement(title,xml,"book","category",NULL,MXML_DESCEND);
            }
    }
    printf("\r\n*****************************程序运行结束*********************************\n");
    mxmlDelete(xml);
    fclose(fp);
    return 0;
}
